<template>
  <div class="ce">
    <hqy-header></hqy-header>
    <div class="article">
      <p class="article_title">{{articleTitle}}</p>
      <span class="article_time">{{createdTime}}</span>
      <div
        class="article_text"
        id="fatherBox"
      ></div>
    </div>
    <footer>
      <div>
        © 2001-2020 华清园教育 | 北京华清园教育科技有限公司 All Rights Reserved. 京ICP备14008487号
      </div>
    </footer>
    <!-- <Sidebar /> -->
  </div>
</template>

<script>
import { artDetail } from '@/api/home.js'
// import Sidebar from '@/components/sidebar'
import HqyHeader from '../../components/header'

export default {
  data () {
    return {
      newsId: '',
      detailHtml: '',
      articleId: '',
      articleTitle: '',
      createdTime: '',
      imgHtml: [],
      department:''
    }
  },
  created () {
    this.articleId = JSON.parse(sessionStorage.getItem("articleId"))
    this.articleTitle = this.articleId.title
    this.createdTime = this.articleId.createdTime
    this.newsId = this.articleId.newId
    this.getLy()
    this.getDetail(this.newsId)
  },
  computed: {
  },
  watch: {

  },
  components: {
    'hqy-header': HqyHeader,
    // Sidebar
  },
  mounted () {
    this.getDetail()
  },
  
  methods: {
    // 乐语
    getLy() {
      var script = document.createElement('script')
      script.type = 'text/javascript'
      script.async = true
      script.src = 'http://op.jiain.net/20004559/10115955.js'
      document.head.appendChild(script)
    },
    getDetail (item) {
      item = this.$route.params.id;
      if(!item){
        /*this.$router.push({
          name: '/index'
        })*/
      }
      console.log(item);
      let arUrl = '/api/HuaQingJYAPIServlet.do?action=4&newsId=' + item
      artDetail(arUrl).then(res => {
        this.detailHtml = res.data.list[0].content
        this.articleTitle = res.data.list[0].title
        this.createdTime = res.data.list[0].createdTime
        let detailAll = document.createElement("div")
        detailAll.innerHTML = this.detailHtml
        this.getAllChildNodes(detailAll.childNodes)
        let fatherBox = document.getElementById('fatherBox')
        fatherBox.innerHTML='';
        fatherBox.appendChild(detailAll)
      }).catch(err => {
        console.log(err)
      })
    },
    getAllChildNodes ($nodeList) {
      $nodeList.forEach((item) => {
        if (item.nodeName == 'IMG') {
          item.outerHTML.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {
            capture = 'http://8.131.241.21:8081' + capture
            item.src = capture
          })
          // item.style.width = '600px'
          // item.style.height = '451px'
        }
        if (item.nodeName == 'P') {
          item.style.textIndent = '2em'
        }
        if (item.childNodes) {
          this.getAllChildNodes(item.childNodes)
        }
      })
    }
  },
  destroyed() {
  },
}

</script>
<style lang='scss' scoped>
@import "./index.scss";
</style>